import axios from 'axios'
const baseURL = process.env.NODE_ENV === 'development' ? '/api' : '';/*ip和端口*/
const SUCCESS_CODE = 200;
const PHOTO_CODE = "id_photo";
const DATA_COOE = "id_data";
const REPLACE_COOD = '_idno_';
const DEFAULT_IMG = '/static/img/user.7dd128a.png';
let photoUrl = '';
let dataUrl = '';
let hasRela = {};/*查找关系的已有数据，用来过滤已有数据*/

export const apiGetConfig = (ev, val) => {/*获取配置*/
	axios.get(baseURL + '/relation/config').then((res) => {
		if (res.status == SUCCESS_CODE) {
			console.log(res);
			res.data.map(item => {
				if (item.code == PHOTO_CODE) { photoUrl = item.url }
				if (item.code == DATA_COOE) { dataUrl = item.url }
			})
		} else {
			console.log("获取配置错误")
		}
		console.log("获取配置结束")
	})
}

export const apiGetInfo = (ev, val) => {/*第一次查身份证*/
	ev.isShowInfo = false;
	ev.echarts_index = false;
	axios.get(baseURL + '/relation/' + val).then((res) => {
		//   	ev.emitRes(res);
		console.log("第一次查身份证")
		if (res.status == SUCCESS_CODE) {
			console.log("第一次查身份证1");
			/*先清空数据*/
			ev.option2.series[0].data = [];
			ev.option2.series[0].links = [];
			let userName = '';
			let userImg = '';
			userImg = getItemInfo(ev, val, 'img');
			/*第一个显示s*/
			//			获取第一个人的图片,名字
			console.log("获取第一个人的图片,名字");
			getItemName(ev, val).then(res_first => {
				console.log(res_first)
				if (res_first.data.data.length == 0) { throwError(ev, '查找不了数据'); return }
				ev.option2.series[0].data.push(
					{
						name: res_first.data.data[0].xm + '$weiyi_' + val,
						"symbol": "image://" + userImg,
						value: 0,
						x: 1125,
						y: 662,
						fixed: true,
						category: 0,
						"symbolSize": 100,
						zjhm: val
					}
				)

				console.log(res);
				if (res.data.length == 0 || res.data == null) { ev.echarts_index = true; return }
				let i = 0;
				res.data.map(item => {
					pushDataAndLink(ev, item.label, 80, 0, false, 0, item.img)/*第一层*/
					item.relations.map(item_relations => {
						pushDataAndLink(ev, item_relations.label, 60, item.label, false, 0, item_relations.img)/*第二层*/
						item_relations.datas.map(item_datas => {
							/*同步姓名*/
							getItemName(ev, item_datas.zjhm).then(res => {
								i++;
								res.data = typeof (res.data) == 'string' ? eval('(' + res.data + ')') : res.data;

								if (res.data.data.length != 0 && res.data.data.length != null) {
									userName = res.data.data[0].xm + '$weiyi_' + item_datas.zjhm + '$id=' + item.id + '$code=' + item_relations.code
									userImg = getItemInfo(ev, item_datas.zjhm, 'img');
									pushDataAndLink(ev, userName, 30, item_relations.label, false, item_datas.zjhm, userImg, item_datas.time)/*第三层*/
								} else {
									pushDataAndLink(ev, item_datas.zjhm + '$weiyi_' + item_datas.zjhm + '$id=' + item.id + '$code=' + item_relations.code, 30, item_relations.label, false, item_datas.zjhm, DEFAULT_IMG, item_datas.time)/*第三层*/
								}
								if (i >= item_relations.datas.length) {/*解决性能问题，只有大于才去执行这个方法*/
									ev.finish();
								}
							}).catch(error => {
								console.log(error)
							})

							/*同步姓名*/
						})
					})
				})
				ev.echarts_index = true;
			}).catch(error => { console.log(error) })
		} else {
			console.log("第一次查身份证错误")
		}
	})
}

/*
 * ev:this,
 * data_name:节点显示的名称，线的目标
 * symbolSize：图片的大小，
 * source_name：线的源头，
 * fixed_true：是否固定,
 * zjhm:身份证，
 * userImg：用户图片,
 * time:次数*分数，字符串
 * code：后台需要
 * ids:后台需要，
 * score：前台显示，分数，
 * label：前台显示：关系名称,
 * allScore：总分，数字，打开详情需要
 * itemTime:每个关系的分数，数字，打开详情需要
 */
function pushDataAndLink(ev, data_name, symbolSize, source_name, fixed_true, zjhm = 0,
	userImg = DEFAULT_IMG, time = 0, code = 0, ids = 0, score = 0, label = "", allScore = 0, itemTime = 0) {/*push进去option2，抽离的方法*/
	ev.option2.series[0].data.push(
		{
			name: data_name,
			"symbol": "image://" + userImg,
			value: 0,
			category: 0,
			fixed: fixed_true,
			"symbolSize": symbolSize,
			zjhm: zjhm,
			itemStyle: {
				normal: {
					borderColor: 'red',
					borderWidth: 4,
					shadowBlur: 10,
					shadowColor: 'red',
					color: 'red',
				}
			},
		}
	);
	ev.option2.series[0].links.push(
		{
			source: source_name,
			target: data_name,
			value: time,
			code: code,
			ids: ids,
			score: score,
			label: label,
			allScore: allScore,
			itemTime: itemTime,
		},
	);
}

function getItemInfo(ev, zjhm, type) {/*根据身份证获取人的信息*/
	if (type == 'img') {
		//		console.log(photoUrl);
		return photoUrl.indexOf(REPLACE_COOD) != -1 ? photoUrl.replace(new RegExp(REPLACE_COOD, 'g'), zjhm.trim()) : photoUrl;/*用户图片*/
	} else if (type == 'name') {
		console.log(dataUrl);
	}
}


function getItemName(ev, zjhm) {/*同步*/
	return new Promise((resolve, reject) => {
		let NewdataUrl = dataUrl.indexOf(REPLACE_COOD) != -1 ? dataUrl.replace(new RegExp(REPLACE_COOD, 'g'), zjhm) : dataUrl;
		axios.get(baseURL + '/relation/forward?url=' + NewdataUrl).then(res => {
			res.data = typeof (res.data) == 'string' ? eval('(' + res.data + ')') : res.data;
			if (res.status == SUCCESS_CODE) {
				resolve(res);
			} else {
				//			 		console.log("同步信息出错")
			}
		}).catch(error => {
			reject(error);
		})
	})
}

function isHasImg(pathImg) {/*验证图片是否存在*/
	var ImgObj = new Image();
	ImgObj.src = pathImg;
	if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
		return true;
	} else {
		return false;
	}
}

function getAge(status) {/*计算年龄*/
	var aDate = new Date();
	var thisYear = aDate.getFullYear();
	//	console.log(status.substring(0,4))
	var brith = status.substring(0, 4)
	var age = (thisYear - brith);
	return age;
}


export const apiClickGetInfo = (ev, val) => {/*左键*/
	//	console.log(val.indexOf('$weiyi_'));
	//	console.log(val.substring(0,val.indexOf("$weiyi_")));
	let sub_val = val.indexOf('$weiyi') == -1 ? val : val.substring(0, val.indexOf("$weiyi_"))
	//	console.log(sub_val)
	axios.get(baseURL + '/relation/' + sub_val).then((res) => {
		if (res.status == SUCCESS_CODE) {
			pushItem(ev, res, val);
		}
	})
}

export const apiShowInfo = (ev, val) => {/*弹出人的信息*/
	console.log(val);
	let sfzName = val.data.zjhm.indexOf("$weiyi_") != -1 ? val.data.zjhm.substring(0, val.data.zjhm.indexOf("$weiyi_")) : val.data.zjhm
	let NewdataUrl = dataUrl.indexOf(REPLACE_COOD) != -1 ? dataUrl.replace(new RegExp(REPLACE_COOD, 'g'), sfzName) : dataUrl;

	axios.get(baseURL + '/relation/forward?url=' + NewdataUrl).then(res => {
		console.log(res);
		console.log(res.data);

		res.data = typeof (res.data) == 'string' ? eval('(' + res.data + ')') : res.data;
		if (res.status == SUCCESS_CODE) {
			console.log(res)
			if (res.data.data.length == 0) { throwError(ev, '查找不了数据'); return }
			res.data.data[0].csrq = getAge(res.data.data[0].csrq);
			let user_img = photoUrl.indexOf(REPLACE_COOD) != -1 ? photoUrl.replace(new RegExp(REPLACE_COOD, 'g'), sfzName) : photoUrl;
			//	 		if(!isHasImg(user_img)){user_img=DEFAULT_IMG}
			res.data.data[0].img_url = user_img
			console.log("弹出人的信息");
			//	 		ev.personInfo.push(res.data.data[0])
			if (ev.type == 'search') {
				ev.personInfo = res.data.data[0]
				ev.isShowInfo = true;
				ev.dragFunc('idNum_' + res.data.data[0].sfzh)
			} else if (ev.type == 'analyse') {
				ev.personInfo.push(res.data.data[0]);
				setTimeout(() => {/*解决vue的先后顺序执行问题*/
					ev.dragFunc('idNum_' + res.data.data[0].sfzh, ev.personInfo.length - 1)
				}, 500)

			}


		} else {
			console.log("弹出人的信息错误")
		}
	})
}



export const apiShowRelation = (ev, val) => {/*查看人的拓展关系*/
	//	console.log(val);
	let sfzNum = val.data.zjhm.indexOf('$weiyi') != -1 ? val.data.zjhm.substring(0, val.data.zjhm.indexOf('$weiyi')) : val.data.zjhm
	//	console.log(sfzNum);
	axios.get(baseURL + '/relation/' + sfzNum).then(res => {
		let userName = '';
		let userImg = '';
		let ImgObj = new Image();
		//		console.log("查看人的关系，图片及其名字");
		let i = 0;
		/*循环开始*/
		res.data.map(item => {
			item.relations.map(item_rela => {
				item_rela.datas.map(item_datas => {
					/*同步姓名*/
					getItemName(ev, item_datas.zjhm).then(res => {
						i++;
						res.data = typeof (res.data) == 'string' ? eval('(' + res.data + ')') : res.data;
						if (res.data.data.length != 0 && res.data.data != null) {
							userName = res.data.data[0].xm
							userImg = getItemInfo(ev, item_datas.zjhm, 'img');
							//								if(!IsExist(userImg)){userImg=DEFAULT_IMG}
							console.log(userImg)
							if (item_datas.zjhm != sfzNum) {/*排除自己*/
								console.log("插入数据")
								//											console.log('长度为：'+item_rela.datas.length);
								//											console.log(filter(ev,userName+'$weiyi_'+item_datas.zjhm))/*有就返回false，无就返回true*/


								if (filter(ev, userName + '$weiyi_' + item_datas.zjhm)) {/*过滤已经有的*/
									ev.option2.series[0].data.push(
										{
											name: userName + '$weiyi_' + item_datas.zjhm,
											"symbol": "image://" + userImg,
											value: 0,
											category: 0,
											fixed: false,
											"symbolSize": 30,
											zjhm: item_datas.zjhm
										}
									)
									hasRela[userName + '$weiyi_' + item_datas.zjhm] = 1;
								} else {
									ev.option2.series[0].links.map(item_link => {
										if (item_link.target == userName + '$weiyi_' + item_datas.zjhm && item_link.source == val.data.name) {/*要指定目标及来源的线*/
											console.log(item_link)
											item_link.value = item_link.value + ',' + Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label;
											item_link.code = item_link.code + ',' + item_rela.code;
											item_link.label = item_link.label + ',' + item_rela.label;
											item_link.score = item_link.score + ',' + item_rela.score;
											item_link.ids = item_link.ids + '$weiyiids_' + item_datas.ids;
											item_link.allScore = item_link.allScore + Number(item_datas.time) * Number(item_rela.score)
											item_link.itemTime = item_link.itemTime + ',' + item_datas.time

										}
									})
								}
								let isPushLink = true;
								ev.option2.series[0].links.map(item_link => {/*筛选出是否已经存在目标和源头刚好相反的线*/
									if (item_link.target == val.data.name && item_link.source == userName + '$weiyi_' + item_datas.zjhm) {/*找到这条线*/
										isPushLink = false;
									}
								})
								if (isPushLink) {
									ev.option2.series[0].links.push(
										{
											source: val.data.name,
											value: Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label,
											target: userName + '$weiyi_' + item_datas.zjhm,
											code: item_rela.code,
											ids: item_datas.ids,
											score: item_rela.score,
											label: item_rela.label,
											allScore: Number(item_datas.time) * Number(item_rela.score),
											itemTime: item_datas.time,
										},
									)
								}

							}
						} else {
							console.log("%c获取不了数据", "color:red");
							//							console.log(res);
							if (filter(ev, item_datas.zjhm + '$weiyi_' + item_datas.zjhm)) {
								ev.option2.series[0].data.push(
									{
										name: item_datas.zjhm + '$weiyi_' + item_datas.zjhm,
										"symbol": "image://" + DEFAULT_IMG,
										value: 0,
										category: 0,
										fixed: false,
										"symbolSize": 30,
										zjhm: item_datas.zjhm,
										itemStyle: {
											normal: {
												borderColor: 'blue',
												borderWidth: 4,
												shadowBlur: 10,
												shadowColor: 'blue',
												color: 'blue',
											}
										},
									}
								)
								hasRela[item_datas.zjhm + '$weiyi_' + item_datas.zjhm] = 1;
							} else {
								ev.option2.series[0].links.map(item_link => {
									if (item_link.target == item_datas.zjhm + '$weiyi_' + item_datas.zjhm && item_link.source == val.data.name) {/*要指定目标及来源的线*/
										console.log(item_link)
										item_link.value = item_link.value + ',' + Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label;
										item_link.code = item_link.code + ',' + item_rela.code;
										item_link.label = item_link.label + ',' + item_rela.label;
										item_link.score = item_link.score + ',' + item_rela.score;
										item_link.ids = item_link.ids + '$weiyiids_' + item_datas.ids;
										item_link.allScore = item_link.allScore + Number(item_datas.time) * Number(item_rela.score)
										item_link.itemTime = item_link.itemTime + ',' + item_datas.time

									}
								})
							}

							let isPushLink = true;
							ev.option2.series[0].links.map(item_link => {/*筛选出是否已经存在目标和源头刚好相反的线*/
								if (item_link.target == val.data.name && item_link.source == item_datas.zjhm + '$weiyi_' + item_datas.zjhm) {/*找到这条线*/
									isPushLink = false;
								}
							})
							if (isPushLink) {
								ev.option2.series[0].links.push(
									{
										source: val.data.name,
										value: Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label,
										target: item_datas.zjhm + '$weiyi_' + item_datas.zjhm,
										code: item_rela.code,
										ids: item_datas.ids,
										score: item_rela.score,
										label: item_rela.label,
										allScore: Number(item_datas.time) * Number(item_rela.score),
										itemTime: item_datas.time,
									},
								)
							}

						}
						if (i >= item_rela.datas.length) {/*解决性能问题*/
							ev.finish();
						}
					})
				})
			})
		})

	})

}


function filter(ev, name) {/*过滤已经有的*/
	//	console.log(name);
	//	console.log(hasRela);
	//	console.log(hasRela[name]);
	if (hasRela[name] == undefined) {
		return true
	}
	return false;
}



export const apiSeachAnalyse = (ev, val, res) => {/*查找关系的第一次*/
	ev.personInfo = [];
	axios.get(baseURL + '/relation/' + val).then(res => {
		console.log('查找关系第一次')
		console.log(res);
		/*先清空数据*/
		ev.option2.series[0].data = [];
		ev.option2.series[0].links = [];
		hasRela = {};
		let userName = '';
		let userImg = '';
		let ImgObj = new Image();
		userImg = getItemInfo(ev, val, 'img');
		//			if(isHasImg(userImg)){userImg=DEFAULT_IMG}
		/*第一个显示s*/
		//			获取第一个人的图片,名字
		console.log("获取第一个人的图片,名字");
		getItemName(ev, val).then(res_first => {
			console.log(res_first)
			if (res_first.data.data.length == 0) { throwError(ev, '查找不了数据'); return }
			ev.option2.series[0].data.push(
				{
					name: res_first.data.data[0].xm + '$weiyi_' + val,
					"symbol": "image://" + userImg,
					value: 0,
					x: 500,
					y: 500,
					fixed: true,
					category: 0,
					"symbolSize": 100,
					zjhm: val
				}
			)
			hasRela[res_first.data.data[0].xm + '$weiyi_' + val] = 1;
			//				循环开始
			let i = 0;
			res.data.map(item => {
				item.relations.map(item_rela => {
					item_rela.datas.map(item_datas => {
						/*同步姓名*/
						getItemName(ev, item_datas.zjhm).then(res => {
							i++;
							res.data = typeof (res.data) == 'string' ? eval('(' + res.data + ')') : res.data;
							console.log(res);
							if (res.data.data.length != 0 && res.data.data != null) {
								userName = res.data.data[0].xm
								userImg = getItemInfo(ev, item_datas.zjhm, 'img');
								//									    hasRela.push(userName+'$weiyi_'+item_datas.zjhm);
								if (filter(ev, userName + '$weiyi_' + item_datas.zjhm)) {
									pushDataAndLink(ev, userName + '$weiyi_' + item_datas.zjhm, 50, res_first.data.data[0].xm + '$weiyi_' + val,
										false, item_datas.zjhm, userImg, Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label, item_rela.code,
										item_datas.ids, item_rela.score, item_rela.label, Number(item_datas.time) * Number(item_rela.score), item_datas.time)/*第三层*/
									hasRela[userName + '$weiyi_' + item_datas.zjhm] = 1;
								} else {
									console.log(item_datas)
									ev.option2.series[0].links.map(item_link => {
										if (item_link.target == userName + '$weiyi_' + item_datas.zjhm && item_link.source == res_first.data.data[0].xm + '$weiyi_' + val) {
											item_link.value = item_link.value + ',' + Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label;
											item_link.code = item_link.code + ',' + item_rela.code;
											item_link.label = item_link.label + ',' + item_rela.label;
											item_link.score = item_link.score + ',' + item_rela.score;
											item_link.ids = item_link.ids + '$weiyiids_' + item_datas.ids;
											item_link.allScore = item_link.allScore + Number(item_datas.time) * Number(item_rela.score)
											item_link.itemTime = item_link.itemTime + ',' + item_datas.time
										}
									})
								}
							} else {/*查不了数据*/
								console.log('查不了数据');
								if (filter(ev, item_datas.zjhm + '$weiyi_' + item_datas.zjhm)) {/*过滤已经有的*/
									hasRela[item_datas.zjhm + '$weiyi_' + item_datas.zjhm] = 1;
									pushDataAndLink(ev, item_datas.zjhm + '$weiyi_' + item_datas.zjhm, 30, res_first.data.data[0].xm + '$weiyi_' + val,
										false, item_datas.zjhm, DEFAULT_IMG, Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label, item_rela.code,
										item_datas.ids, item_rela.score, item_rela.label, Number(item_datas.time) * Number(item_rela.score), item_datas.time)/*第三层*/
								} else {
									ev.option2.series[0].links.map(item_link => {
										if (item_link.target == item_datas.zjhm + '$weiyi_' + item_datas.zjhm && item_link.source == res_first.data.data[0].xm + '$weiyi_' + val) {
											item_link.value = item_link.value + ',' + Number(item_datas.time) * Number(item_rela.score) + '分' + item_rela.label;
											item_link.code = item_link.code + ',' + item_rela.code;
											item_link.label = item_link.label + ',' + item_rela.label;
											item_link.score = item_link.score + ',' + item_rela.score;
											item_link.ids = item_link.ids + '$weiyiids_' + item_datas.ids;
											item_link.allScore = item_link.allScore + Number(item_datas.time) * Number(item_rela.score)
											item_link.itemTime = item_link.itemTime + ',' + item_datas.time
										}
									})
								}

							}
							console.log(item_rela.datas.length)
							console.log(i);
							if (i >= item_rela.datas.length) {/*解决过多的查询引发的性能问题*/
								ev.finish();
							}

						}).catch(error => {
							console.log(error)
						})
						/*同步姓名*/
					})
				})
			})
			ev.echart_analyse = true;
		}).catch(error => { console.log(error) })
	})
}


async function IsExist(url)/*图片是否存在*/ {
	console.log("进入IsExist")
	await new Promise((resolve, reject) => {

		let img = new Image();
		img.src = url;
		img.addEventListener("load", () => {
			console.log("dwada");
			resolve(true);
		})
		img.addEventListener("error", () => {
			console.log("222");
			reject(false);
		})
	})

}


function PromiseImg(url) {
	console.log("进入PromiseImg")
	return new Promise((resolve, reject) => {
		let img = new Image();
		img.addEventListener("load", () => {
			console.log("dwada");
			resolve(true);
		})
		img.addEventListener("error", () => {
			reject(false);
		})
		img.src = url;
	})
}


//定义抠图方法
/*
 * 
 * imgSrc:图片地址，
 * 
 * radius：半径
 * 
 * center：x,y,一般为0 0 
 * 
 * */
function getImgData(imgSrc, radius, center = {
	x: 0,
	y: 0
}) {
	return new Promise((resolve) => {
		const canvas = document.createElement('canvas');
		const contex = canvas.getContext('2d');
		const img = new Image();
		img.crossOrigin = '';
		const diameter = 2 * radius;
		img.onload = function () {
			canvas.width = diameter;
			canvas.height = diameter;
			contex.clearRect(0, 0, diameter, diameter);
			contex.save();
			contex.beginPath();
			contex.arc(radius, radius, radius, 0, 2 * Math.PI); //画出圆
			contex.clip(); //裁剪上面的圆形
			contex.drawImage(img, center.x - radius, center.y - radius, diameter, diameter, 0, 0, diameter, diameter); // 在刚刚裁剪的园上画图
			contex.restore(); // 还原状态
			resolve(canvas.toDataURL('image/png', 1))
		}
		img.src = imgSrc;
	})
}

//function axiosShowInfo(ev,i=0,code_array,ids_array,score_arr,label_arr,val){
//	if(i==code_array.length){
//		return;
//	}
//			axios({
//				method:'get',
//				url:baseURL+'/relation/data/'+code_array[i]+'?ids='+encodeURIComponent(ids_array[i]),
//			}).then(res=>{
//				ev.analyse.firstTable.firstName = val.data.source.indexOf('$weiyi_')==-1?val.data.source:val.data.source.substring(0,val.data.source.indexOf('$weiyi_'));
//				ev.analyse.firstTable.firstSFZ=val.data.source.indexOf('$weiyi_')==-1?val.data.source:val.data.source.substring(val.data.source.indexOf('$weiyi_')+7,val.data.source.length);
//				ev.analyse.firstTable.gxzs = val.data.allScore;
//				ev.analyse.firstTable.secName = val.data.target.indexOf('$weiyi_')==-1?val.data.target:val.data.target.substring(0,val.data.target.indexOf('$weiyi_'));
//	    		ev.analyse.firstTable.secSFZ = val.data.target.indexOf('$weiyi_')==-1?val.data.target:val.data.target.substring(val.data.target.indexOf('$weiyi_')+7,val.data.target.length);
//	    		ev.analyse.tableData1.push({rele_type:val.data.score_arr[i],rele_num:val.data.code_array[i],rele_name:val.data.label_arr[i]})
//	    		axiosShowInfo(ev,i+1,code_array,ids_array,score_arr,label_arr,val)
//			})
//	
//	
//}

/*关系分析*/
export const apiClickEdge = (ev, val) => {/*点击线,弹出详情*/
	console.log(val)
	let code_array = String(val.data.code).split(',')
	let ids_array = String(val.data.ids).split('$weiyiids_');
	let score_arr = String(val.data.score).split(',');
	let label_arr = String(val.data.label).split(',');
	let time_arr = String(val.data.itemTime).split(',');

	console.log(code_array);
	console.log(ids_array);
	ev.analyse.tableData1 = [];/*先清空*/
	ev.analyse.table3 = [];/*先清空*/
	//	axiosShowInfo(ev,0,code_array,ids_array,score_arr,label_arr,val);
	for (let i = 0; i < code_array.length; i++) {
		axios({
			method: 'get',
			url: baseURL + '/relation/data/' + code_array[i] + '?ids=' + encodeURIComponent(ids_array[i]),
		}).then(res => {
			ev.analyse.firstTable.firstName = val.data.source.indexOf('$weiyi_') == -1 ? val.data.source : val.data.source.substring(0, val.data.source.indexOf('$weiyi_'));
			ev.analyse.firstTable.firstSFZ = val.data.source.indexOf('$weiyi_') == -1 ? val.data.source : val.data.source.substring(val.data.source.indexOf('$weiyi_') + 7, val.data.source.length);
			ev.analyse.firstTable.gxzs = val.data.allScore;
			ev.analyse.firstTable.secName = val.data.target.indexOf('$weiyi_') == -1 ? val.data.target : val.data.target.substring(0, val.data.target.indexOf('$weiyi_'));
			ev.analyse.firstTable.secSFZ = val.data.target.indexOf('$weiyi_') == -1 ? val.data.target : val.data.target.substring(val.data.target.indexOf('$weiyi_') + 7, val.data.target.length);
			ev.analyse.tableData1.push({ rele_type: score_arr[i], rele_num: time_arr[i], rele_name: label_arr[i] })
			ev.analyse.table3.push(
				{
					name: label_arr[i],
					myself: val.data.source.indexOf('$weiyi_') == -1 ? val.data.source : val.data.source.substring(0, val.data.source.indexOf('$weiyi_')),
					tableLable3: res.data.header,
					tableData3: res.data.hasOwnProperty('result') && res.data.result.constructor === Array ? res.data.result : '',
				}
			)

		})
	}

}


function throwError(ev, msg) {
	ev.$message({
		message: msg,
		type: "error",
		showClose: true,
	});
}


export const getURLinfo = (ev) => {/*获取url信息*/
	console.log(ev.$route);
	if (ev.$route.query.hasOwnProperty('info')) {
		//		console.log(ev.$route.query.info.split('_'))
		let arr1 = ev.$route.query.info.split('_');
		if (arr1.length == 2) {
			ev.form.input1 = String(arr1[1])
			ev.cliclSearchImg();
		}
		if (ev.$route.query.hasOwnProperty('token')) {
			ev.token = ev.$route.query.token
		}

	} else {
		return;
	}
}

export const getScoreVal = (ev) => {/*获取分值*/
	axios.get(baseURL + '/relations').then(res => {
		console.log(res);
		ev.scoreVal = res.data
	})
}
